package com.jse.io.nio.network.old.muti;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

import com.jse.io.nio.network.old.StreamUtil;


public class ClientTask implements Runnable {
	private String name;
	private Socket socket;
	
	public ClientTask(String name, Socket socket) {
		this.name = name;
		this.socket = socket;
	}

	@Override
	public void run() {
		OutputStream out = null;
		//读取服务器端信息
		InputStream input = null;
		try {
			out = socket.getOutputStream();
			input = socket.getInputStream();
			
			String output = name + " is running";
			out.write(output.getBytes());
			out.flush();
			System.out.println("client: " + output);
			
			if (input != null) {
				StreamUtil.getReaderString(input);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
//				out.close();
//				socket.close();
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
	}

}
